package com.hx.er.action.admin.food;

import org.springframework.beans.factory.annotation.Autowired;

import com.hx.er.action.base.ErAdminAction;
import com.hx.er.bean.detail.LabelDetailBean;
import com.hx.er.common.system.Constants;
import com.hx.er.common.system.ErLanguages;
import com.hx.er.common.system.ErProperties;
import com.hx.er.common.util.StringUtil;
import com.hx.er.service.admin.IAdminFoodService;

public class AdminLabelDeleteAction extends ErAdminAction {

	// 序列化ID
	private static final long serialVersionUID = -5885896269081800347L;

	// 标签编号
	private long labelId;

	// 多语言标签名
	private String labelLang1;
	private String labelLang2;
	private String labelLang3;
	private String labelLang4;
	private String labelLang5;

	// 页面日期
	private String startDate;
	private String endDate;

	// 标签对象
	private LabelDetailBean labelDetailBean;

	@Autowired
	private IAdminFoodService adminFoodService;

	public String init() {
		// 初始化页面
		this.initPage();

		return SUCCESS;
	}

	public String delete() {
		this.labelDetailBean.setLabelId(this.labelId);
		this.labelDetailBean.setUpdateUserId(super.getUserInfoLogin().getUserId());
		int count = this.adminFoodService.deleteLabel(this.labelDetailBean);
		
		if (count == 0) {
			this.addActionError(super.getText(DELETE_FAILURE_MSG));
			this.initPage();
			return INPUT;
		} else {
			this.addActionMessage(super.getText(DELETE_SUCCESS_MSG));
			return SUCCESS;
		}
	}

	private void initPage() {
		this.labelDetailBean = this.adminFoodService.getLabelDetailAliveById(this.labelId);

		this.startDate = StringUtil.formatDateStr(this.labelDetailBean.getStartDate(), ErProperties.getProperty(Constants.PROPERTY_COMMON_DATETIME_FORMAT));
		this.endDate = StringUtil.formatDateStr(this.labelDetailBean.getEndDate(), ErProperties.getProperty(Constants.PROPERTY_COMMON_DATETIME_FORMAT));

		// 语言
		if (ErLanguages.getLangList().size() > 0) {
			this.labelLang1 = ErLanguages.getLocale(ErLanguages.getLangList().get(0).getLangId()).getLanguage().toUpperCase();
		}
		if (ErLanguages.getLangList().size() > 1) {
			this.labelLang2 = ErLanguages.getLocale(ErLanguages.getLangList().get(1).getLangId()).getLanguage().toUpperCase();
		}
		if (ErLanguages.getLangList().size() > 2) {
			this.labelLang3 = ErLanguages.getLocale(ErLanguages.getLangList().get(2).getLangId()).getLanguage().toUpperCase();
		}
		if (ErLanguages.getLangList().size() > 3) {
			this.labelLang4 = ErLanguages.getLocale(ErLanguages.getLangList().get(3).getLangId()).getLanguage().toUpperCase();
		}
		if (ErLanguages.getLangList().size() > 4) {
			this.labelLang5 = ErLanguages.getLocale(ErLanguages.getLangList().get(4).getLangId()).getLanguage().toUpperCase();
		}
	}

	public String getLabelLang1() {
		return labelLang1;
	}

	public void setLabelLang1(String labelLang1) {
		this.labelLang1 = labelLang1;
	}

	public String getLabelLang2() {
		return labelLang2;
	}

	public void setLabelLang2(String labelLang2) {
		this.labelLang2 = labelLang2;
	}

	public String getLabelLang3() {
		return labelLang3;
	}

	public void setLabelLang3(String labelLang3) {
		this.labelLang3 = labelLang3;
	}

	public String getLabelLang4() {
		return labelLang4;
	}

	public void setLabelLang4(String labelLang4) {
		this.labelLang4 = labelLang4;
	}

	public String getLabelLang5() {
		return labelLang5;
	}

	public void setLabelLang5(String labelLang5) {
		this.labelLang5 = labelLang5;
	}

	public LabelDetailBean getLabelDetailBean() {
		return labelDetailBean;
	}

	public void setLabelDetailBean(LabelDetailBean labelDetailBean) {
		this.labelDetailBean = labelDetailBean;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public long getLabelId() {
		return labelId;
	}

	public void setLabelId(long labelId) {
		this.labelId = labelId;
	}
}
